home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H145.ZIP / ASXXXX_3.ZIP / MOND09.ASM < prev    next >
Assembly Source File  |  1990-07-18  |  55KB  |  2,290 lines

  1.     .title    MONDEB - 09
  2.  
  3.     ;    *********************************************************
  4.     ;    *                            *
  5.     ;    *    MONDEB - 09  -  a monitor/debugger        *
  6.     ;    *        for the 6809  microprocessor        *
  7.     ;    *                            *
  8.     ;    *********************************************************
  9.     ;
  10.     ; author:    Don Peters    (6800 version)
  11.     ; date:        April 1977
  12.     ;
  13.     ; modified for the 6809
  14.     ; by:        Alan R. Baldwin
  15.     ; date:        Nov 1988    
  16.     ;
  17.     ;      This 6809 monitor/debugger does not use the
  18.     ;    direct page addressing mode.  Thus the user
  19.     ;    program has complete control of the page
  20.     ;    assignment and may use the monitor routines
  21.     ;    without concern for variable locations.
  22.     ;
  23.     ;      To add user functions to MONDEB - 09
  24.     ;
  25.     ;    1) add your commands to the end of command list #1
  26.     ;    2) add the command entry points to the jump table
  27.     ;    3) append any local command lists after MONDEB's
  28.     ;    4) provide an external initialization routine to
  29.     ;        set up the console (and/or alternate)
  30.     ;        ports and any other start up processing.
  31.     ;       MONDEB will call 'userinit' if inituser = 1.
  32.     ;
  33.  
  34.     .module    mond09
  35.  
  36.     standalone = 0    ; standalone flag indicating the
  37.             ; vectors and associated code are
  38.             ; to be included during assembly
  39.  
  40.     inituser = 0    ; call 'userinit' flag indicating
  41.             ; a user startup routine will be
  42.             ; called during intialization
  43.  
  44.     .page
  45.     .sbttl    MONDEB - 09 working variables
  46.  
  47.     .radix    d
  48.  
  49.     .if    standalone
  50.  
  51.     .area    WORKPG    (REL,CON)
  52.  
  53.     .else
  54.  
  55.     .area    WORKPG    (ABS,OVR)
  56.  
  57.     .endif
  58.  
  59.     .setdp    0
  60.  
  61. workpg:    .blkb    256-(endpg-mstack)
  62.             ; main stack storage
  63. mstack:    .blkb    12    ; stack storage for rti instruction
  64.  
  65. ttybuf:    .blkb    72    ; start of input line buffer
  66. ttyend:    .blkb    1    ; end of input line buffer
  67. bufbeg:    .blkb    2    ; input line start of buffer
  68. bufend:    .blkb    2    ; input line end of buffer
  69.  
  70. comadr:    .blkb    2    ; address of beginning of command lists
  71. synptr:    .blkb    2    ; input line character pointer for good syntax
  72. linptr:    .blkb    2    ; input line character pointer (content =>
  73.             ; content of synptr)
  74. bolflg:    .blkb    1    ; "beginning of line flg"
  75. delim:    .blkb    1    ; characters permitted as valid command/modifier
  76.             ; delimiter
  77. ibcode:    .blkb    1    ; input base (1=hex, 2=dec, 3=oct)
  78. dbcode:    .blkb    1    ; display base (1=hex, 2=dec, 3=oct, 4=bin)
  79. dbnbr:    .blkb    1    ; display base number (e.g., 16,10,8, or 2)
  80. nbrhi:    .blkb    1    ; most significant byte of scanned number
  81. nbrlo:    .blkb    1    ; least significant byte of scanned number
  82. ranglo:    .blkb    2    ; range lower limit picked up by gtrang
  83. ranghi:    .blkb    2    ; range upper limit picked up by gtrang
  84. verfrm:    .blkb    2    ; beginning address of range to verify
  85. verto:    .blkb    2    ; ending address of range to checksum verify
  86. chksum:    .blkb    1    ; checksum of range given in the verify command
  87. brkadr: .blkb    2    ; address of inserted breakpoint
  88. brkins:    .blkb    1    ; instruction which should be there normally
  89. inpflg:    .blkb    1    ; alternate input flag
  90. outflg:    .blkb    1    ; alternate output flag
  91. outadr:    .blkb    2    ; alternate address that the output chars go to
  92. hdxflg:    .blkb    1    ; half-duplex terminal flag (if non-zero, no echo)
  93. cplcnt:    .blkb    1    ; "characters per line" count
  94. cplmax:    .blkb    1    ; "characters per line" maximum
  95.  
  96.     ; temporary (locally used) variables
  97.  
  98. temp1:    .blkb    2    ; in: main
  99. temp2:    .blkb    2    ; in: main
  100. temp3:    .blkb    2    ; in: main
  101. temp4:    .blkb    2    ; in: main
  102. temp5:    .blkb    2    ; in: main
  103. temp6:    .blkb    2    ; in: main
  104.  
  105. nummat:    .blkb    1    ; used in command
  106. lisnum:    .blkb    1    ; used in command
  107. comnum:    .blkb    1    ; used in command
  108. lisptr:    .blkb    2    ; used in command
  109. decdig:    .blkb    1    ; decimal digit being built
  110. numbhi:    .blkb    1    ; used by outnum
  111. numblo:    .blkb    1    ; used by outnum
  112. nbr2x:    .blkb    2    ; used by number
  113. timcon:    .blkb    2    ; delay time constant
  114. bytect:    .blkb    1    ; record byte count used in load command
  115. cksm:    .blkb    1    ; record checksum used in load command
  116.  
  117. conin:    .blkb    2    ; address of console input routine
  118. conout:    .blkb    2    ; address of console output routine
  119. altin:    .blkb    2    ; address of alternate input routine
  120. altout:    .blkb    2    ; address of alternate output routine
  121.  
  122. .rsrvd:    .blkb    2    ; reserved vector
  123. .swi3:    .blkb    2    ; swi3 vector
  124. .swi2:    .blkb    2    ; swi2 vector
  125. .firq:    .blkb    2    ; firq vector
  126. .irq:    .blkb    2    ; irq vector
  127. .swi:    .blkb    2    ; swi vector
  128. .nmi:    .blkb    2    ; nmi vector
  129. spsave:    .blkb    2    ; saved stack pointer
  130. endpg:
  131.  
  132.     ; convenient equivalences for local variables
  133.  
  134. memadr    =    temp1    ; display, set, search, test
  135. strnum    =    temp2    ; fndstr
  136. eoschr    =    temp2+1    ; fndstr
  137.  
  138.     ; for "search" command
  139.  
  140. bytptr    =    temp2
  141. nbytes    =    temp3
  142. nbrmat    =    temp3+1
  143. bytstr    =    temp4
  144.  
  145.     ; other constants
  146.  
  147. cr    =    13    ; carriage return
  148. lf    =    10    ; line feed
  149.  
  150.  
  151.     .page
  152.     .sbttl    MOND09 Startup
  153.  
  154.     .if    standalone
  155.  
  156.     .area    MONDEB    (REL,CON)
  157.  
  158. reset:    lds    #mstack+12    ; load stack pointer
  159.     bsr    mond09        ; stack pc and start mondeb
  160.     bra    reset
  161.     .else
  162.  
  163.     .area    MONDEB    (ABS,OVR)
  164.  
  165.     .endif
  166.  
  167. mond09:    pshs    u,y,x,dp,b,a,cc    ; pseudo swi
  168.     sts    spsave        ; save the pointer
  169.     orcc    #0b01010000    ; hold irq and firq interrupts
  170.     lds    #mstack        ; initialize the stack pointer
  171.     jsr    inital        ; initialize variables
  172.     jsr    docrlf        ; advance to a clean line
  173.     ldx    #msghed        ; get address of header
  174.     jsr    outstr        ; type it
  175.     ldx    #ttybuf-1    ; get address of terminal input buffer
  176.     stx    bufbeg        ; save it
  177.     ldx    #ttyend        ; define end of input buffer
  178.     stx    bufend        ; 72 char capacity, incl cr
  179.     lda    #3        ; delimiter class definition
  180.     sta     delim        ; space or comma (code 3)
  181.     bra    promp1
  182.  
  183.     ; prepare to get a new command
  184.  
  185. prompt:    jsr    docrlf    ; type cr-lf
  186.     inc    bolflg    ; set 'beginning of line' flag
  187.     ldx     synptr    ; point to current character
  188.     lda    ,x    ; get it
  189.     cmpa    #';    ; semicolon?
  190.     beq    getcmd    ; continue scan if it is, 
  191.             ; skipping the prompt
  192. promp1:    ldx    #msgprm    ; type prompt
  193.     jsr    outstr
  194.     jsr    getlin    ; get line of input
  195.     cmpb    #3    ; abort line on a control-c
  196.     beq    prompt
  197.  
  198.     ldx    bufbeg    ; set syntax scanning pointer
  199.     stx    synptr    ; to beginning of buffer/line
  200.     lda    1,x    ; get first char
  201.     jsr    tsteol    ; reprompt on an empty line
  202.     beq    prompt    ; (first char = cr,lf,or ;)
  203.  
  204.     .page
  205.     .sbttl    Get Command
  206.  
  207. getcmd:    lda    #1    ; use list 1 when matching
  208.     jsr    comand    ; now go for a match
  209.     beq    prompt    ; reprompt if just a cr was typed
  210.     bgt    jmpcmd    ; good command if positive    
  211.  
  212. badsyn: ldx    bufbeg    ; get start of line
  213.  
  214. 1$:    cpx    linptr    ; space over to the error in syntax
  215.     beq    2$    ; at error ?
  216.     jsr     outsp    ; output a space
  217.     inx        ; no, move on
  218.     bra    1$
  219.  
  220.     ; the 'extra' char '1' is compensated for by the prompt
  221.     ; char on the preceeding line
  222.  
  223. 2$:    lda    #'^    ; at error - get an up-arrow
  224.     jsr    outchr    ; print it
  225.     jsr    docrlf
  226.     bra    promp1    ; ignore any succeeding packed
  227.             ; commands
  228.  
  229.     ; *******
  230.     ; *there should be no more characters on the input line
  231.     ;    (except delimiters)
  232.  
  233. nomore:    jsr    skpdlm
  234.     bcs    prompt    ; if carry bit set, end of line
  235.             ; (normal)
  236.     bra    badsyn    ; there is something there but shouldn't be
  237.  
  238.     .page
  239.     .sbttl    Command Dispatcher
  240.  
  241.     ; ******
  242.     ; execute a computed 'goto' to the proper command
  243.  
  244. jmpcmd:    asla        ; multiply command by 2
  245.     ldx    #1$-2
  246.     jmp    [a,x]    ; jump to designated command
  247.  
  248. 1$:    .word    break
  249.     .word    contin
  250.     .word    compar
  251.     .word    copy
  252.     .word    displa
  253.     .word    dbase
  254.     .word    delay
  255.     .word    dump
  256.     .word    goto
  257.     .word    help
  258.     .word    ibase
  259.     .word    load
  260.     .word    reg
  261.     .word    set
  262.     .word    search
  263.     .word    test
  264.     .word    verify
  265.     .word    cli
  266.     .word    clf
  267.     .word    sei
  268.     .word    sef
  269.     .word    xirq
  270.     .word    xfirq
  271.     .word    xnmi
  272.     .word    xrsrvd
  273.     .word    xswi
  274.     .word    xswi2
  275.     .word    xswi3
  276.  
  277.     .page
  278.     .sbttl    REG - display registers
  279.  
  280. reg:            ; print stack stored swi data
  281. disreg:    ldx    spsave    ; get saved stack pointer
  282.     clr    comnum    ; start at beginning of the
  283.             ; register name list
  284.     bsr    1$    ; type condition codes
  285.     bsr    1$    ; type acca
  286.     bsr    1$    ; type accb
  287.     bsr    1$    ; type dp
  288.     jsr    docrlf    ; advance to a clean line
  289.     bsr    2$    ; type index reg x
  290.     bsr    2$    ; type index reg y
  291.     bsr    2$    ; type index reg u
  292.     jsr    docrlf    ; advance to a clean line
  293.     leax    -9,x    ; back to d
  294.     bsr    2$    ; type d
  295.     leax    7,x    ; back to pc
  296.     bsr    2$    ; type program counter
  297.  
  298.     ; type the stack pointer location
  299.  
  300.     bsr    3$    ; type stack pointer id
  301.     ldx    #spsave
  302.     jsr    out2by    ; type the value
  303.     jmp    nomore
  304.  
  305.     ; output content of a 1 byte register
  306.  
  307. 1$:    bsr    3$
  308.     jsr    out1by
  309.     inx
  310.     rts
  311.  
  312.     ; output content of a 2 byte register
  313.  
  314. 2$:    bsr    3$
  315.     jsr    out2by
  316.     leax    2,x    ; skip to next word in stack
  317.     rts
  318.  
  319.     ; misc setup for register display
  320.  
  321. 3$:    jsr    outsp    ; output a space
  322.     inc    comnum    ; skip to next register name
  323.     lda    #5    ; register name is in list 5
  324.     jsr    typcmd    ; type it
  325.     jsr    outeq    ; type an '='
  326.     rts
  327.  
  328.     .page
  329.     .sbttl    Software Interrupt Entry Point
  330.  
  331. typswi:    sts    spsave
  332.     ldx    #msgswi
  333.     jsr    outstr
  334.  
  335.     ; decrement pc so it points to 'swi' instruction
  336.  
  337.     ldx    spsave
  338.     ldd    10,x
  339.     subd    #1
  340.     cmpd    brkadr    ; a break point ?
  341.     bne    disreg    ; no - allow to pass
  342.     std    10,x    ; backup PC
  343.     bra    disreg    ; go display registers
  344.  
  345.     .sbttl    GOTO - Go To Memory Address
  346.  
  347. goto:    jsr    mnumber    ; get destination
  348.     beq    contin    ; if none, just continue
  349.     ldd    nbrhi
  350.     lds    spsave    ; place new PC
  351.     std    10,s    ; fall through to Continue
  352.  
  353.     .sbttl    Continue - Continue From a 'SWI'
  354.  
  355. contin:    lds    spsave    ; in case sp was modified via set
  356.     rti        ; command
  357.  
  358.     .sbttl    SEI - Set Interrupt Mask
  359.  
  360. sei:    orcc    #0b00010000
  361.     jmp    nomore
  362.  
  363.     .sbttl    CLI - Clear Interrupt Mask
  364.  
  365. cli:    andcc    #~0b00010000
  366.     jmp    nomore
  367.  
  368.     .sbttl    SEF - Set Fast Interrupt Mask
  369.  
  370. sef:    orcc    #0b01000000
  371.     jmp    nomore
  372.  
  373.     .sbttl    CLF - Clear Fast Interrupt Mask
  374.  
  375. clf:    andcc    #~0b01000000
  376.     jmp    nomore
  377.  
  378.     .page
  379.     .sbttl    COPY - Copy From One Location To Another
  380.  
  381. copy:    jsr    gtrang    ; get source range into ranglo &
  382.             ; ranghi
  383.     lble    badsyn    ; error if no source
  384.     jsr    mnumber    ; get destination
  385.     lble    badsyn    ; error if no destination
  386.     ldx    ranglo    ; get source address pointer
  387.     ldu    nbrhi    ; get destination address pointer
  388.     lda    ,x    ; get byte from source
  389. 1$:    sta    ,u+    ; save byte in destination
  390.     cpx    ranghi    ; compare to end of input range
  391.     lbeq    nomore    ; done if equal
  392.     lda    ,x+    ; get byte from source
  393.     bra    1$    ; loop for next byte
  394.  
  395.     .page
  396.     .sbttl    BREAK - Set Breakpoint at Specified Address
  397.  
  398. break:    jsr    mnumber    ; get breakpoint location
  399.     bmi    3$    ; if not numeric, look for '?'
  400.     beq    2$    ; if no modifier, remove old breakpoint
  401.     ldx    brkadr    ; get current break address
  402.     lda    ,x    ; and the char there
  403.     cmpa    #0x3f    ; compare to 'swi'
  404.     bne    1$    ; equal?
  405.     lda    brkins    ; yes, restore the old instruction
  406.     sta    ,x    ; restore it
  407.  
  408. 1$:    ldx    nbrhi    ; get new breakpoint
  409.     stx    brkadr    ; save it
  410.     lda    ,x    ; get instruction stored there
  411.     sta    brkins    ; save it
  412.     lda    #0x3f    ; get code for software interrupt
  413.     sta    ,x    ; put it at breakpoint
  414.     bra    5$    ; all done
  415.  
  416. 2$:    ldx    brkadr    ; get address of break
  417.     lda    ,x    ; get inst. there
  418.     cmpa    #0x3f    ; swi?
  419.     bne    5$    ; if not, return & prompt
  420.     lda    brkins    ; was a swi - get previous inst.
  421.     sta    ,x    ; & restore it
  422.     bra    5$
  423.  
  424. 3$:    lda     #4
  425.     jsr    comand    ; scan for it
  426.     lble    badsyn    ; bad syntax if not '?'
  427.     ldx    brkadr    ; it is, get break address
  428.     lda    ,x    ; get instruction there
  429.     cmpa    #0x3f    ; is it a 'swi'?
  430.     beq    4$    ; if yes, say so
  431.     ldx    #msgnbr    ; get that message
  432.     jsr    outstr    ; say it
  433.     bra    5$
  434.  
  435. 4$:    ldx    #msgbat    ; get that message
  436.     jsr    outstr    ; say it
  437.     ldx    #brkadr    ; get break address
  438.     jsr    out2by    ; type it
  439. 5$:    jmp    nomore
  440.  
  441.     .page
  442.     .sbttl    IBASE - Set Input Base
  443.  
  444. ibase:    lda    #3    ; look for hex,dec,or oct in list #3
  445.     jsr    comand
  446.     bmi    2$    ; unrecognizable base, try'?'
  447.     bgt    1$
  448.     lda    #1    ; no base given - default to hex
  449. 1$:    sta    ibcode    ; save base code
  450.     jmp    nomore
  451.  
  452. 2$:    lda    ibcode    ; get ib code in case its needed
  453.     pshs    a    ; save it on stack temporarily
  454.     bra    ibdbq
  455.  
  456.     .sbttl    DBASE - Set Display Base
  457.  
  458. dbase:    lda    #3    ; look for hex,dec,oct, or bin in list #3
  459.     jsr    comand
  460.     bmi    3$    ; unrecognizable base, try '?'
  461.     bgt    1$
  462.     lda    #1    ; no base given - default to hex
  463. 1$:    sta    dbcode
  464.     ldx    #2$-1    ; get numeric base from table
  465.     lda    a,x
  466.     sta    dbnbr    ; save it
  467.     jmp    nomore    ; done
  468.  
  469. 2$:    .byte    16    ; display base table
  470.     .byte    10
  471.     .byte    8
  472.     .byte    2
  473.  
  474. 3$:    lda    dbcode    ; get db code in case its needed
  475.     pshs a        ; save it on stack temporarily
  476.  
  477. ibdbq:    lda    #4    ; look for '?' in list #4
  478.     jsr    comand    
  479.     puls b        ; retrieve input base/display base code
  480.     lble    badsyn    ; error if the 'something' was not a '?'
  481.     lda    #3    ; base code is in list 3
  482.     stb    comnum    ; store base code
  483.     jsr    typcmd    ; type out base
  484.     jmp    nomore
  485.  
  486.     .page
  487.     .sbttl    Display - Display Memory Data
  488.  
  489. displa:    jsr    gtrang    ; get memory display range
  490.     lble    badsyn    ; address is required
  491.     ldx    ranglo    ; initialize address pointer
  492.     stx    memadr
  493.  
  494.     lda    #6    ; search list 6 for
  495.     jsr    comand    ; display modifiers 'data' or 'used'
  496.     lbmi    badsyn    ; any other modifier is illegal
  497.     deca        ; adj display modifier code so that:
  498.     sta    comnum    ; -1=addr & data, 0=data, 1=used
  499.     clrb        ; init 'data values per line' counter
  500.     incb
  501. 1$:    ldx    #memadr
  502.     tst    comnum    ; which display option?
  503.     bmi    6$    ; if 'address & data', go there
  504.     decb        ; count data values per line
  505.     bne    2$    ; if count not up, skip address output
  506.     jsr    docrlf    ; get to line beginning
  507.     jsr    out2by    ; output address
  508.     jsr    outsp    ; and a space
  509.     ldb    dbnbr    ; reset line counter
  510.  
  511. 2$:    ldx    memadr    ; point to data at that address
  512.     tst    comnum    ; want 'data' option?
  513.     bgt    3$    ; if not, go to 'used' code
  514.  
  515.     jsr    outsp    ; output preceedng space
  516.     bra     7$
  517.  
  518. 3$:    lda    ,x    ; get the data
  519.     bne     4$
  520.     lda    #'.    ; its zero, get a '.'
  521.     bra     5$
  522.  
  523. 4$:    lda    #'+    ; its non-zero, get a '+'
  524. 5$:    jsr    outchr    ; output the '.' or '+'
  525.     bra    8$
  526.  
  527. 6$:    jsr    outsp    ; output a preceeding space
  528.     jsr    out2by    ; type address
  529.     jsr    outeq    ; type    '='
  530.     ldx    ,x    ; get content
  531. 7$:    jsr    out1by    ; type it
  532. 8$:    cpx    ranghi    ; are we done
  533.     lbeq    nomore    ; if yes, back to prompt
  534.     inx        ; no, inc memory address
  535.     stx    memadr    ; save it
  536.     bra    1$
  537.  
  538.     .page
  539.     .sbttl    SET - Set Memory Locations
  540.  
  541. set:    jsr    gtrang    ; get memory location/range
  542.     bmi    5$    ; if not an address, look for a
  543.             ; register name
  544.     lbeq    badsyn    ; an address modifier is required
  545.  
  546.     ; range of address specified?
  547.  
  548.     ldx    ranglo
  549.     cpx    ranghi
  550.     beq    2$    ; if single address, set up
  551.             ; addresses individually
  552.  
  553.     ; set a range of addresses to a single value
  554.  
  555.     jsr    mnumber    ; get that value
  556.     lble    badsyn    ; its    required
  557.     lda    nbrlo    ; put it in acca
  558. 1$:    sta    ,x    ; store it in destination
  559.     cpx    ranghi    ; end of range hit?
  560.     lbeq    nomore    ; if yes, all done
  561.     inx        ; no, on to next address in range
  562.     bra    1$    ; loop to see it
  563.  
  564.     ; set addresses up individually
  565.  
  566. 2$:    stx    memadr    ; save memory loc
  567. 3$:    jsr    mnumber    ; get data to put there
  568.     beq    4$    ; end of line?
  569.     lblt    badsyn    ; abort if bad syntax
  570.     lda    nbrlo    ; load data byte
  571.     ldx    memadr    ; load address
  572.     sta    ,x+    ; store data
  573.     bra    2$
  574.  
  575. 4$:    ldx    synptr    ; point to end of line
  576.     lda    ,x    ; get char there
  577.     cmpa    #lf    ; line feed?
  578.     lbne    nomore    ; if not,back to prompt
  579.     ldx    #memadr    ; yes, get next address to be set
  580.     jsr    out2by    ; type it
  581.     jsr    outsp    ; and a space
  582.     jsr    getlin    ; get a new line
  583.     ldx    bufbeg    ; get buffer beginning
  584.     stx    synptr    ; equate it to syntax scan pointer
  585.     bra    3$    ; go pick up data
  586.  
  587.     ; look for (register name, register value) pairs
  588.  
  589. 5$:    lda    #5    
  590.     jsr    comand    ; pick up a register name
  591.     lbmi    badsyn    ; error if unrecognizable
  592.     lbeq    nomore    ; done if end of line
  593.     pshs a        ; save register name(number)
  594.     jsr    mnumber    ; get new register value
  595.     puls a        ; restore register name(number)
  596.     lble    badsyn    ; got good register value?
  597.     deca
  598.     ldu    #6$
  599.     lda    a,u
  600.     leau    a,u
  601.     ldx    spsave    ; yes, point to top of stack
  602.     ldd    nbrhi    ; get register value
  603.     jsr    ,u    ; go to function
  604.     bra    5$    ; and loop
  605.  
  606. 6$:    .byte    7$-6$
  607.     .byte    8$-6$
  608.     .byte    9$-6$
  609.     .byte    10$-6$
  610.     .byte    11$-6$
  611.     .byte    12$-6$
  612.     .byte    13$-6$
  613.     .byte    14$-6$
  614.     .byte    15$-6$
  615.     .byte    16$-6$
  616.  
  617. 7$:    stb    ,x    ; condition codes
  618.     rts
  619.  
  620. 8$:    stb    1,x    ; acca
  621.     rts
  622.  
  623. 9$:    stb    2,x    ; accb
  624.     rts
  625.  
  626. 10$:    stb    3,x    ; dp
  627.     rts
  628.  
  629. 11$:    std    4,x    ; ix
  630.     rts
  631.  
  632. 12$:    std    6,x    ; iy
  633.     rts
  634.  
  635. 13$:    std    8,x    ; iu
  636.     rts
  637.  
  638. 14$:    std    1,x    ; d
  639.     rts
  640.  
  641. 15$:    std    10,x    ; pc
  642.     rts
  643.  
  644. 16$:    std    spsave    ; sp
  645.     rts
  646.  
  647.     .page
  648.     .sbttl    Checksum Verify a Block of Memory
  649.  
  650. verify:    jsr    gtrang    ; get a number range
  651.     beq    1$    ; no modifier means check what we have
  652.     lbmi    badsyn    ; anything else is illegal
  653.  
  654.     ldx    ranglo    ; good range given,
  655.     stx    verfrm    ; transfer it to checksum addresses
  656.     ldx    ranghi
  657.     stx    verto
  658.  
  659.     bsr    cksum    ; compute checksum
  660.     sta    chksum    ; save it
  661.     ldx    #chksum    ; type the checksum
  662.     jsr    out1by
  663.     bra    3$
  664.  
  665. 1$:    bsr    cksum    ; compute checksum
  666.     cmpa     chksum    ; same as stored checksum?
  667.     bne     2$
  668.  
  669.     ldx    #msgver    ; they verify - say so
  670.     jsr    outstr
  671.     bra    3$
  672.  
  673. 2$:    ldx    #msgnve    ; they don't - say so
  674.     jsr    outstr
  675. 3$:    jmp    nomore
  676.  
  677.     ; compute the checksum from addresses verfrm to verto
  678.     ; return the checksum in acca
  679.  
  680. cksum:    clra        ; init checksum to zero
  681.     ldx    verfrm    ; get first address
  682.     dex        ; init to one less
  683. 1$:    inx        ; start of checksum loop
  684.     adda    ,x    ; update checksum in acca with
  685.             ; byte pointed to
  686.     cpx    verto    ; hit end of range?
  687.     bne    1$    ; if not, loop back
  688.     coma        ; complement the sum
  689.     rts        ; return with it
  690.  
  691.  
  692.     .page
  693.     .sbttl    Search Memory for Byte String
  694.  
  695.     ; global variables used
  696.     ;  linptr - input line character pointer
  697.     ;  lisptr - command list character pointer
  698.     ;  ranglo - 'search from' address
  699.     ;  ranghi - 'search to' address
  700.     ;
  701.     ; local variables used
  702.     ;  memadr - starting memory address where a match
  703.     ;        occurred
  704.     ;  bytptr - address pointer used to fill bytstr and
  705.     ;        substr buffers
  706.     ;  nbytes - number of bytes in byte string
  707.     ;  nbrmat - number of chars that match so far in the
  708.     ;        matching process
  709.     ;  bytstr - starting address of 6 character byte sring
  710.     ;        buffer
  711.     ;
  712.     ; the search string occupies temp4, temp5, & temp6
  713.     ;        (6 bytes max)
  714.  
  715. search:    jsr    gtrang    ; get search range
  716.     lble    badsyn    ; abort if no pair
  717.     ldx    #bytstr    ; get start of byte string
  718.             ; to search for
  719.     stx    bytptr    ; set pointer to it
  720.     clr    nbytes    ; zero # of bytes in byte string
  721.  
  722. 1$:    jsr    mnumber    ; get a byte string
  723.     beq    2$    ; begin search if eol
  724.     lblt    badsyn    
  725.             ; good byte, add it to string
  726.     inc    nbytes    ; count this  byte
  727.     lda    nbytes    ; don't accept over 6 bytes
  728.     cmpa    #6
  729.     lbgt    badsyn
  730.     lda    nbrlo    ; get (low order) byte
  731.     ldx    bytptr    ; get byte pointer
  732.     sta    ,x+    ; save byte, bump pointer
  733.     stx    bytptr    ; save it
  734.     bra     1$
  735.  
  736. 2$:    tst    nbytes    ; is # of bytes to look for >0
  737.     lbeq    badsyn    ; if not,bad syntax
  738.     ldx    ranglo    ; initialize memory pointer
  739.     dex
  740.     stx    linptr
  741.  
  742. 3$:    ldx  #bytstr-1    ; initialize byte pointer
  743.     stx    lisptr
  744.     clr    nbrmat    ; set 'number of bytes that
  745.             ; matched' to zero
  746.     jsr    getlst    ; get byte from byte string
  747.  
  748. 4$:    jsr    mgetchr    ; get byte from memory range
  749.     cba        ; compare memory & byte string
  750.             ; characters
  751.     beq    5$    ; if no match, test for range end
  752.     cpx    ranghi    ; have we reached the range
  753.             ; search upper limit?
  754.     lbeq    nomore    ; yes, go prompt for next command
  755.     bra    4$
  756.  
  757. 5$:    stx    memadr    ; match achieved - save address of match
  758. 6$:    inc    nbrmat    ; bump number matched
  759.     lda    nbrmat    
  760.     cmpa    nbytes    ; have all characters matched?
  761.     beq    8$    ; if so, match achieved
  762.  
  763.     jsr    getlst    ; haven't matched all yet, go get next pair
  764.     jsr    mgetchr    ; even if past 'search to' address
  765.     cba
  766.     beq    6$
  767.  
  768. 7$:    ldx    memadr    ; mismatch on some byte past the first one
  769.  
  770.     cpx    ranghi    ; this test handles special case
  771.     lbeq    nomore    ; of a match on range end
  772.     stx    linptr
  773.     bra     3$    ; go reset the byte string pointer
  774.  
  775.  
  776. 8$:    ldx    #memadr    ; match on byte string achieved,
  777.     jsr    out2by    ; type out memory address
  778.     jsr    outsp    ; and a space
  779.     bra     7$
  780.  
  781.     .page
  782.     .sbttl    Test Ram
  783.  
  784. test:    jsr    gtrang    ; get an address range
  785.     lble    badsyn    ; abort if no pair
  786.     ldu    ranglo    ; ranglo holds starting address of range
  787.             ; ranghi holds ending address of range
  788. 1$:    lda    ,u    ; get byte stored at test location
  789.     pshs    a    ; save it
  790.     clr    ,u    ; zero the location
  791.     tst    ,u    ; test it
  792.     beq    2$    ; ok if = zero
  793.     ldx    #msgccl    ; can't clear location
  794.     bra    4$
  795.  
  796. 2$:    dec    ,u    ; set location to $ff
  797.     lda    #0xff
  798.     cmpa    ,u    ; did it get set to $ff?
  799.     beq    3$
  800.     ldx    #msgcso    ; can't set location to one's
  801.     bra     4$
  802.  
  803. 3$:    puls    a
  804.     sta    ,u    ; restore previous content
  805.     cmpu    ranghi    ; hit end of test range?
  806.     lbeq    nomore    ; yes, all done
  807.     leau    1,u    ; no, move to test next location
  808.     bra    1$
  809.  
  810. 4$:    stx    temp3    ; save error message temporarily
  811.     ldx    #temp4
  812.     stu    ,x
  813.     jsr    out2by    ; type out bad address
  814.     jsr    outeq    ; and equal sign
  815.     ldx    temp4
  816.     jsr    out1by    ; its content
  817.     jsr    outsp    ; a space
  818.     ldx    temp3
  819.     jsr    outstr    ; and the type of error
  820.     jsr    docrlf    
  821.     bra    3$
  822.  
  823.     .page
  824.     .sbttl    vector settup commands
  825.  
  826.     ; rsrvd - set up rsvd pointer
  827.  
  828. xrsrvd:    jsr    numinx    ; get pointer in ix
  829.     stx    .rsrvd    ; save it
  830.     jmp    nomore
  831.  
  832.     ; swi3 - set up swi3 pointer
  833.  
  834. xswi3:    jsr    numinx    ; get pointer in ix
  835.     stx    .swi3    ; save it
  836.     jmp    nomore
  837.  
  838.     ; swi2 - set up swi2 pointer
  839.  
  840. xswi2:    jsr    numinx    ; get pointer in ix
  841.     stx    .swi2    ; save it
  842.     jmp    nomore
  843.  
  844.     ; firq - set up interrupt pointer
  845.  
  846. xfirq:    jsr    numinx    ; get pointer in ix
  847.     stx    .firq    ; save it
  848.     jmp    nomore
  849.  
  850.     ; irq - set up interrupt pointer
  851.  
  852. xirq:    jsr    numinx    ; get pointer in ix
  853.     stx    .irq    ; save it
  854.     jmp    nomore
  855.  
  856.     ; swi - set up swi pointer
  857.  
  858. xswi:    jsr    numinx    ; get pointer in ix
  859.     stx    .swi    ; save it
  860.     jmp    nomore
  861.  
  862.     ; nmi - set up non-maskable interrupt pointer
  863.  
  864. xnmi:    jsr     numinx    ; get ponter in ix
  865.     stx    .nmi    ; save it
  866.     jmp    nomore
  867.  
  868.     .page
  869.     .sbttl    compare numbers
  870.  
  871.     ; compare - output sum & difference of two input numbers
  872.  
  873. compar:    jsr    numinx    ; get first number
  874.     stx    ranglo    ; put it in ranglo
  875.     jsr    numinx    ; get second number
  876.     stx    nbrhi    ; save it in nbrhi
  877.  
  878.     ; compute and output the sum
  879.  
  880.     jsr    sumnum    ; compute sum
  881.     ldx    #msgsis    ;get its title
  882.     bsr    1$    ; output title & sum
  883.  
  884.     jsr    difnum    ; compute difference
  885.     ldx    #msgdis    ; get its title
  886.     bsr    1$    ; output title & diff
  887.  
  888.     jmp    nomore
  889.  
  890.     ; compute and output the result
  891.  
  892. 1$:    jsr    outstr    ; output it
  893.     ldx    #ranghi    ; get result
  894.     jsr    out2by    ; display result
  895.     rts
  896.  
  897.     .page
  898.     .sbttl    dump memory in S1-S9 format
  899.  
  900.     ; *****
  901.     ; dump - dump portion of memory in S1-S9 format
  902.     ;
  903.     ; get address range: start in ranglo (2 bytes), end in
  904.     ;        ranghi (2bytes)
  905.     ; if no address range is given, use whatever is n
  906.     ;        ranlo & ranghi
  907.  
  908. dump:    jsr    gtrang
  909.     clr    temp5    ; initialize to dump to terminal
  910.  
  911. 1$:    lda    #2    ; look for a 'TO' modifier
  912.     jsr    comand
  913.     beq    2$
  914.     lble    badsyn    ; error if bad syntax
  915.     cmpa    #1    ; TO ?
  916.     bne    1$    ; go look for another modifier
  917.  
  918.     jsr    numinx    ; get 'TO' address
  919.     stx    outadr    ; save it
  920.     inc    temp5    ; remember this
  921.     bra    1$    ; go look for another modifier
  922.  
  923. 2$:    tst    temp5
  924.     beq    3$
  925.     inc    outflg    ; set flag for proper output device
  926.  
  927. 3$:    ldd    ranghi    ; compute # of bytes to output
  928.     subd    ranglo    ; subtract lo bytes
  929.     cmpd    #16    ; diff 0-15.
  930.     bcs    5$    
  931. 4$:    ldb    #15
  932.  
  933.     ; to get frame count, add 1
  934.     ; (diff of 0 implies 1 output) + # of data bytes
  935.     ; + 2 addr bytes + 1 checksum byte
  936.  
  937. 5$:    addb    #4
  938.     stb    temp3    ; temp3 is the frame count
  939.     subb    #3
  940.     stb    temp4    ; temp4 is the record byte count
  941.  
  942.     ldx    #msgs1    ; output a 'S1' header data record
  943.     jsr    outstr
  944.     clrb        ; zero checksum
  945.  
  946.     ldx    #temp3    ; punch frame count
  947.     bsr    7$
  948.  
  949.     ldx    #ranglo    ; punch address
  950.     bsr    7$
  951.     bsr    7$
  952.  
  953.     ldx    ranglo    ; load memory pointer
  954. 6$:    bsr    7$    ; output data byte
  955.     dec    temp4    ; dec byte count
  956.     bne    6$
  957.     stx    ranglo    ; save memory pointer
  958.  
  959.     comb        ; complement checksum
  960.     pshs    b    ; put it on stack
  961.     tfr    s,x    ; let ix point to it
  962.     bsr    7$    ; output checksum
  963.     puls    b    ; pull it off stack
  964.     ldx    ranglo    ; restore memory pointer
  965.     dex
  966.     cpx    ranghi     ; hit end of range?
  967.     bne    3$
  968.  
  969.     ldx    #msgs9    ; yes, output an 'S9' record
  970.     jsr    outstr
  971.     clr    outflg    ; set to terminal output
  972.     jmp     nomore
  973.  
  974. 7$:    jsr    out1by    ; output a byte pointed to by ix as
  975.     addb    ,x+    ; 2 hex characters, update checksum
  976.     rts
  977.  
  978.  
  979.     .page
  980.     .sbttl    Load S1-S9 format Data
  981.  
  982. load:    jsr    inpchr    ; get a char
  983.     cmpa    #'S    ; is it an S ?
  984.     bne    load
  985.  
  986.     jsr    inpchr    ; got an 'S', examine next character
  987.     cmpa    #'9    ; done if its a '9'
  988.     beq    3$
  989.  
  990.     cmpa    #'1    ; is it a '1'?
  991.     bne    load    ; if not, look for next 'S'
  992.  
  993.     clr    cksm    ; clear checksum
  994.  
  995.     jsr    5$    ; read record byte count
  996.     suba    #2
  997.     sta    bytect    ; save count minus 2 address bytes
  998.  
  999.     bsr    4$    ; build address
  1000.  
  1001. 1$:    bsr    5$    ; read a data byte into acca
  1002.     dec    bytect    ; count it
  1003.     beq    2$    ; if done with record, check checksum
  1004.     sta    ,x+    ; not done, store byte in memory
  1005.     bra    1$    ; on to next memory address
  1006.  
  1007. 2$:    inc     cksm    ; test checksum by adding 1
  1008.     beq    load    ; if ok, result should be zero
  1009.  
  1010.     ldx    #msgnve    ; record checksum error
  1011.     jsr    outstr
  1012.     ldx    #temp1    ; get record address of it
  1013.     jsr    out2by    ; type it too
  1014. 3$:    clr    inpflg    ; reset flag to normal terminal input
  1015.     jmp     nomore
  1016.  
  1017. 4$:    bsr    5$    ; build address
  1018.     sta    temp1
  1019.     bsr    5$
  1020.     sta    temp1+1
  1021.     ldx    temp1
  1022.     rts
  1023.  
  1024. 5$:    bsr    6$    ; get left hex digit
  1025.     asla        ; move to hi 4 bits
  1026.     asla
  1027.     asla
  1028.     asla
  1029.     tab        ; save it in acca
  1030.     bsr    6$    ; get right hex digit
  1031.     aba        ; combine then in acca
  1032.     tab        ; update the checksum
  1033.     addb    cksm
  1034.     stb    cksm
  1035.     rts
  1036.  
  1037. 6$:    jsr    inpchr    ; input a hex char & convert to internal form
  1038.     suba    #'0
  1039.     bmi    8$    ; not hex if below ascii '1'
  1040.     cmpa    #'9-'0
  1041.     ble    7$    ; ok if ascii '9' or less
  1042.     cmpa    #'A-'0    ; below ascii 'A'?
  1043.     bmi    8$    ; error if it is
  1044.     cmpa    #'F-'0    ; over ascii 'F'?
  1045.     bgt    8$    ; error if it is
  1046.     suba    #7    ; conv ascii A-F to hex A-F
  1047. 7$:    rts
  1048.  
  1049. 8$:    ldx    #msgcnh    ; error - char not hex, say so
  1050.     jsr    outstr
  1051.     rts
  1052.  
  1053.     .page
  1054.     .sbttl    Delay Function
  1055.  
  1056.     ; *****
  1057.     ; delay - delay specified # of milliseconds
  1058.  
  1059. delay:    jsr    numinx    ; get delay time
  1060.     bsr    timdel
  1061.     jmp    nomore
  1062.  
  1063.     ; *****
  1064.     ; time delay subroutine
  1065.     ; ix is input as the # of milliseconds to delay
  1066.     ; adj timcon so (7*timcon*cycle time=1 ms)
  1067.  
  1068. timdel:    pshs    d
  1069. 1$:    ldd    timcon
  1070.  
  1071. 2$:    subd    #1    ; a 7 cycle loop
  1072.     bne    2$
  1073.  
  1074.     dex        ; decrement millisecond counter
  1075.     bne    1$
  1076.     puls    d,pc
  1077.  
  1078.     .page
  1079.     .sbttl    Help List
  1080.  
  1081. help:    jsr    docrlf    ; next line
  1082.     ldx    #comlst    ; command list
  1083.  
  1084. 1$:    ldb    #4    ; commands per line
  1085.     stb    temp1
  1086.  
  1087. 2$:    ldb    #12    ; positions per command
  1088.             ; must be larger than longest command
  1089. 3$:    lda    ,x+    ; get character
  1090.     cmpa    #cr    ; <cr> is end of command
  1091.     beq    4$
  1092.     jsr    outchr    ; print command character
  1093.     decb
  1094.     bne    3$
  1095.  
  1096. 4$:    lda    ,x    ; get character
  1097.     cmpa    #lf    ; <lf> is end of list
  1098.     beq    6$    ; finished
  1099.     dec    temp1    ; per line done ?
  1100.     bne    5$    ; no - skip
  1101.  
  1102.     jsr    docrlf    ; next line
  1103.     bra    1$
  1104.  
  1105. 5$:    lda    #'     ; space
  1106.     jsr    outchr
  1107.     decb
  1108.     bne    5$
  1109.     bra    2$
  1110.  
  1111. 6$:    jsr    docrlf    ; next line
  1112.     jmp    nomore
  1113.  
  1114.     .page
  1115.     .sbttl    Command Lists
  1116.  
  1117.     ;================================================
  1118.     ;
  1119.     ; c o m m a n d   l i s t   s c a n n i n g 
  1120.     ;    r o u t i n e
  1121.     ;
  1122.     ; this routine seeks a match of the characters pointed
  1123.     ; at by the input line scanning pointer to one of the
  1124.     ; commands in a list specified by acca.
  1125.     ; the result of the scan for a match is returned in
  1126.     ; acca as follows:
  1127.     ;
  1128.     ;    acca=-1: the match was unsuccessful. the syntax
  1129.     ;         pointer (synptr) was not updated
  1130.     ;            (advanced).
  1131.     ;
  1132.     ;    acca= 0: the match was unsuccessful since there
  1133.     ;            were
  1134.     ;          no more characters, i.e., the end of
  1135.     ;            the
  1136.     ;        line was reached.
  1137.     ;
  1138.     ;    acca=+n: successful match. the syntax pointer
  1139.     ;            was updated
  1140.     ;         to the first character following the 
  1141.     ;          command
  1142.     ;          delimiter.  acca holds the number of
  1143.     ;              the
  1144.     ;          command matched.
  1145.     ; global variables for external communication
  1146.     ; synptr - good syntax input line char pointer
  1147.     ; linptr - input line character pointer
  1148.     ; delim - class of permissible command delimiters
  1149.     ;
  1150.     ; temporary 2 byte internal variables
  1151.     ; lisptr - command list character pointer
  1152.     ;
  1153.     ; temporary 1 byte internal variables
  1154.     ; nummat - number of characters that successfully match
  1155.     ; lisnum - # of list within which a match will be sought
  1156.     ; comnum - command number matched
  1157.     ;
  1158.     ; constants used
  1159.     ; cr - carriage return
  1160.     ; lf - line feed
  1161.     ;
  1162.     ; a, b & ix are not preserved
  1163.  
  1164. comand:    sta    lisnum    ; save list # to match within
  1165.     jsr    skpdlm    ; test if we are at the end of the line
  1166.     bcc    1$
  1167.     clra
  1168.     rts
  1169.  
  1170.     ; initialize the command list pointer to one less than
  1171.     ;         the beginning of the command lists
  1172.  
  1173. 1$:    ldx    comadr    ; entry point
  1174.  
  1175.     ; move to the beginning of the desired command list
  1176.  
  1177.     lda    lisnum    ; search for 'string' # lisnum
  1178.     ldb    #lf    ; use lf as a 'string' terminator
  1179.     bsr    fndstr
  1180.     stx    lisptr
  1181.  
  1182.     ; the list pointer, lisptr, now points to one less than
  1183.     ; the first character
  1184.     ; of the first command in the desired list
  1185.  
  1186.     clr    comnum
  1187.  
  1188.     ; reset input line pointer to: 1) beginning of line, or
  1189.     ; to 2) point where last successful scan terminated
  1190.  
  1191. 2$:    inc    comnum    ; initialize the command # to 1
  1192.     ldx    synptr
  1193.     stx    linptr
  1194.     clr    nummat    ; clear number of characters
  1195.             ; matched
  1196. 3$:    jsr    mgetchr    ; get input line char in accb
  1197.     jsr    tstdlm    ; test for a delimiter
  1198.     bne    4$    ; success (found delimiter)
  1199.     jsr    getlst    ; get command list char in acca
  1200.     cmpa    #lf    ; has end of command list been reached ?
  1201.     beq    5$    ; if so, potential match failure
  1202.     cmpa    #cr    ; has end of command been reached ?
  1203.     beq    5$    ; if so, potential match failure
  1204.     cba        ; compare the two characters
  1205.     bne    6$    ; match not possible on this command
  1206.     inc    nummat    ; they match, compare the succeeding characters
  1207.     bra    3$    ; inc number of characters matched
  1208.  
  1209. 4$:    ldx    linptr    ; successful match
  1210.     stx    synptr    ; update good syntax pointer
  1211.     lda    comnum    ; return command number
  1212.     rts
  1213.  
  1214.     ; no match
  1215.  
  1216. 5$:    tst    nummat    ; did at least one match?
  1217.     beq    6$    ; to next command if none matched
  1218.     jsr    tstdlm    ; at least one matched - test for delimiter
  1219.     bne    4$    ; if a delimiter, match has been achieved
  1220.     lda    ,x    ; retrieve last character
  1221.  
  1222.     ; illegal delimiter
  1223.     ; move to next command within list
  1224.  
  1225. 6$:    cmpa    #lf    ; end of this list?
  1226.     beq    7$    ; if so, nothing on list matched
  1227.     cmpa    #cr    ; is it a cr?
  1228.     beq    2$    ; yes, next command
  1229.     jsr    getlst    ; get next command list character
  1230.     bra    6$    ; no, get to end of command
  1231.  
  1232. 7$:    clra    ; match failure
  1233.     deca    ; no match possible within this list
  1234.     rts
  1235.  
  1236.     .page
  1237.     .sbttl    Typeout Command
  1238.  
  1239.     ;====================================
  1240.     ; this routine types out command number "comnum"
  1241.     ; the list is specified in acca
  1242.     ; accb & ix are preserved
  1243.  
  1244. typcmd:    pshs    b,x
  1245.     ldx  #comlst-1    ; move to head of command lists
  1246.     ldb    #lf    ; and list terminator
  1247.     bsr    fndstr    ; go to head of desired list
  1248.     lda    comnum    ; get command number
  1249.     ldb    #cr    ; get command terminator
  1250.     bsr    fndstr    ; go to head of desired command
  1251.  
  1252. 1$:    inx        ; move to next character
  1253.     lda    ,x    ; get a command character
  1254.     cmpa    #cr    ; is it a command terminator?
  1255.     beq    2$    ; if so, return
  1256.     jsr    outchr    ; no, type it
  1257.     bra    1$
  1258.  
  1259. 2$:    puls    b,x,pc
  1260.  
  1261.     .page
  1262.     .sbttl    Find string
  1263.  
  1264.     ;======================================
  1265.     ; move to beginning of desired string number (in acca)
  1266.     ; each string is terminated by an end of string
  1267.     ;   character (in accb)
  1268.     ; the index register is assumed initialized pointing to
  1269.     ; one less than the first character of the first string
  1270.     ; acca, accb & ix are not preserved
  1271.     ; local variables
  1272.     ; strnum - string # to find
  1273.     ; eoschr - "end of string" character
  1274.  
  1275. fndstr:    sta    strnum    ; save string number
  1276.     stb    eoschr    ; save terminator
  1277.     clrb
  1278. 1$:    incb        ; string 1 is the first string
  1279.     cmpb    strnum    ; is this the right string?
  1280.     beq    3$    ; if so, done
  1281.  
  1282.     ; no, swallow up characters until an end of string char is hit
  1283.  
  1284. 2$:    inx        ; bump pointer to next one
  1285.     lda    ,x    ; get char pointed at
  1286.     cmpa    eoschr    ; end of string hit?
  1287.     beq    1$    ; if it is, bump the string counter
  1288.     bra    2$    ; no, move on to next char
  1289. 3$:    rts        ; ix set properly, return
  1290.  
  1291.     .page
  1292.     .sbttl    Skip Leading Delimiters
  1293.  
  1294.     ;=================================================
  1295.     ; skip leading delimiters
  1296.     ; this routine should be called prior to scanning for
  1297.     ; any information
  1298.     ; on the input line
  1299.     ; the current character is ignored if the scannng
  1300.     ; pointer is at the beginning of a line. if not, the
  1301.     ; scanning pointer skips over spaces and commas
  1302.     ; until an end of line or non-delimiter is found.
  1303.     ; the carry bit is set if and end of line is encountered.
  1304.  
  1305.     ; acca, accb, & ix are not preserved
  1306.  
  1307. skpdlm:    clc
  1308.     tst    bolflg    ; at beginning of line?
  1309.     bgt    2$
  1310.  
  1311.     ; look at current input character
  1312.  
  1313. 1$:    ldx    synptr    ; get pointer to it
  1314.     lda    ,x    ; get char
  1315.     bsr    tsteol    ; test for end of line
  1316.     bne    2$
  1317.     sec        ; yes, end hit, set carry
  1318.     rts
  1319.  
  1320.     ; "peek" at next char in line
  1321.  
  1322. 2$:    ldb    1,x    ; get it
  1323.     bsr    tstdlm    ; see if its a delimiter
  1324.     bne    3$
  1325.     rts        ; if not, return
  1326.  
  1327.     ; next char is a delimiter
  1328.  
  1329. 3$:    jsr    mgetchr    ; move to next char in input line
  1330.     stx    synptr    ; update syntax pointer
  1331.     bra    1$    ; go test for end of line
  1332.  
  1333.  
  1334.     .page
  1335.     .sbttl    Test for End-of-Line Character
  1336.  
  1337.     ;============================================
  1338.     ; test for end-of-line character
  1339.     ; z bit of cc reg set if char in acca is a terminator
  1340.     ; acca, accb, & ix are preserved
  1341.  
  1342. tsteol:    cmpa    #cr    ; carriage return?
  1343.     beq    1$
  1344.     cmpa    #lf    ; line feed? (continued lines)
  1345.     beq    1$
  1346.     cmpa    #';    ; for several commands on one line
  1347. 1$:    rts
  1348.  
  1349.     .sbttl    Test for Delimeter
  1350.  
  1351.     ;===============================================
  1352.     ; check the character n accb aganst the delimiter(s) 
  1353.     ; specified by variable delim
  1354.     ; accb & ix are preserved
  1355.     ; acca is set to 0 if accb is not a delimiter, to 1
  1356.     ; if it is
  1357.     ;  if delim=1, space s delimiter
  1358.     ;  if delim=2, comma is delimiter
  1359.     ;  if delim=3, space or comma is delimiter
  1360.     ;  if delim=4, any non-alphanumeric is a delimiter
  1361.     ; test for end-of-line (logical or physical)
  1362.  
  1363. tstdlm:    pshs b
  1364.     tba
  1365.     bsr    tsteol
  1366.     puls b
  1367.     beq    5$
  1368.  
  1369.     lda    delim
  1370.     cmpa    #1
  1371.     bne    1$
  1372.     cmpb    #'     ; want a space - is it?
  1373.     bne    6$
  1374.     bra    5$
  1375.  
  1376. 1$:    cmpa    #2
  1377.     bne    3$
  1378. 2$:    cmpb    #',    ; want a comma - is it?
  1379.     bne    6$
  1380.     bra    5$
  1381. 3$:    cmpa    #3
  1382.     bne    4$
  1383.     cmpb    #'     ; want either, is it a space?
  1384.     beq    5$
  1385.     bra    2$    ; or a comma?
  1386.  
  1387. 4$:    cmpa    #4
  1388.     bne    7$    ; error if delm not 1-4
  1389.     cmpb    #'0    ; test if char is 0-9 inclusive
  1390.     blt    5$
  1391.     cmpb    #'9
  1392.     ble    6$
  1393.  
  1394.     cmpb    #'A    ; test if char is A to Z inclusive
  1395.     blt    5$
  1396.     cmpb    #'Z
  1397.     ble    6$    ; over Z - its a delimiter
  1398.  
  1399. 5$:    lda    #1    ; char in accb is a delimiter
  1400.     rts
  1401.  
  1402. 6$:    clra        ; char in accb is not a delimiter
  1403.     rts
  1404.             ; error in specifying delimiter class
  1405. 7$:    swi        ; have monitor type out pertinent
  1406.             ; statistics
  1407.  
  1408.     .page
  1409.     .sbttl    Sum Two Numbers
  1410.  
  1411.     ;================================================
  1412.     ; add the 2 byte number stored in (ranglo,ranglo+1) to 
  1413.     ; the number stored in (nbrhi,nbrlo) and put the result
  1414.     ; in (ranghi,ranghi+1)
  1415.  
  1416. sumnum:    pshs    d    ; add lo order bytes
  1417.     ldd    ranglo
  1418.     addd    nbrhi
  1419.     std    ranghi
  1420.     puls    d,pc
  1421.  
  1422.     .sbttl    Subtract Two Numbers
  1423.  
  1424.     ;====================================================
  1425.     ; subtract the 2 byte number stored in (nbrhi,nbrlo)
  1426.     ; from the two byte number stored in (ranglo,ranglo+1)
  1427.     ; and put the result in (ranghi,ranghi+1)
  1428.     ; accb & ix are preserved
  1429.     ; acca is altered
  1430.  
  1431. difnum:    pshs    d    ; subtract lo order bytes
  1432.     ldd    ranglo
  1433.     subd    nbrhi
  1434.     std    ranghi
  1435.     puls    d,pc
  1436.  
  1437.     .page
  1438.     .sbttl    Get Range
  1439.  
  1440.     ;===================================================
  1441.     ; this routine scans the input line for a pair of numbers
  1442.     ; representing an address range. a colon separating the
  1443.     ; pair implies "thru", while an "!" implies "thru the
  1444.     ; following"
  1445.     ; e.g., 100:105 is equivalent to 100!5
  1446.     ; a single number implies a range of 1
  1447.     ; on return (ranglo,ranglo+1) holds the range start, and
  1448.     ; (ranghi,ranghi+1) holds the range end
  1449.     ; acca, accb, & ix are not preserved
  1450.  
  1451. gtrang:    bsr    mnumber    ; pick up first number
  1452.     bgt    1$
  1453.     blt    2$
  1454.     rts        ; nothing more on input line
  1455.  
  1456.  
  1457. 1$:    ldx    nbrhi    ; good single number
  1458.     stx    ranglo    ; transfer it to ranglo
  1459.     bra    3$    ; and to ranghi
  1460.  
  1461.     ; bad number, but is it bad due to a ":" or "!" delimiter?
  1462.     ; get the terminator for the first number
  1463.  
  1464. 2$:    ldx    linptr
  1465.     lda    ,x
  1466.     cmpa    #':    ; was it a colon?
  1467.     bne    4$    ; if not, go test for "!"
  1468.     bsr    8$    ; was ":", process first number &
  1469.             ; get next one
  1470.     ble    5$    ; illegal if end of line or non-numeric
  1471.  
  1472. 3$:    ldx    nbrhi    ; transfer second number to ranghi
  1473.     stx    ranghi
  1474.     bra    7$
  1475.  
  1476. 4$:    cmpa    #'!    ; was delimiter a "!"?
  1477.     beq    6$    ; if yes, get 2nd number
  1478.     clra        ; illegal delimiter, return
  1479.     deca
  1480. 5$:    rts
  1481.  
  1482. 6$:    bsr    8$    ; was "!", process first number &
  1483.             ; get next one
  1484.     ble    5$
  1485.     bsr    sumnum    ; compute range end, put into ranghi
  1486.  
  1487. 7$:    lda    #1    ; successful exit
  1488.     rts
  1489.  
  1490.     ; update syntax pointer, move first number to ranglo,
  1491.     ; & get 2nd number
  1492.  
  1493. 8$:    stx    synptr    ; update syntax pointer
  1494.     ldx    nbrhi    ; get first number of the pair
  1495.     stx    ranglo    ; save it in "low range" value
  1496.     bsr    mnumber    ; pick up the second number of the pair
  1497.     rts
  1498.  
  1499.     .page
  1500.     .sbttl    Get number in IX
  1501.  
  1502.     ;====================================================
  1503.     ; get a 2 byte number & return it in the index register
  1504.  
  1505. numinx:    bsr    mnumber
  1506.     bgt    1$
  1507.     jmp    badsyn
  1508. 1$:    ldx    nbrhi
  1509.     rts
  1510.  
  1511.     .page
  1512.     .sbttl    Scan For a Number
  1513.  
  1514.     ;==================================================
  1515.     ; scan for a number
  1516.     ; return the most significant byte in nbrhi
  1517.     ; and the least significant byte in nbrlo
  1518.     ; the result of the scan for a number is returned in
  1519.     ; acca as follows:
  1520.     ;
  1521.     ;    acca=-1: the match was unsuccessful. the syntax
  1522.     ;        pointer (synptr) was not updated.
  1523.     ;
  1524.     ;    acca= 0: the scan was unsuccessful since there
  1525.     ;        were no more characters. (i.e., the end
  1526.     ;        of the line was encountered.)
  1527.     ;
  1528.     ;    acca=+1: the scan was successful. the syntax
  1529.     ;        pointer was updated to the first character
  1530.     ;        following the command.
  1531.     ;
  1532.     ; ix is preserved
  1533.     ; global variables for external communication
  1534.     ; nbrhi - number hi byte
  1535.     ; nbrlo - number lo byte
  1536.     ; ibcode - input base code
  1537.     ; dbcode - display base code
  1538.     ;
  1539.     ; local variables
  1540.     ; nbr2x - used in decimal conversion
  1541.     ; initialize both bytes to zero
  1542.  
  1543. mnumber:pshs    x    ; save ix
  1544.     clr    nbrhi
  1545.     clr    nbrlo
  1546.     ldx    synptr    ; initialize the line scanning pointer
  1547.     stx    linptr
  1548.     jsr    skpdlm    ; are we at end of line?
  1549.     bcc    1$
  1550.     clra        ; yes, zero acca
  1551.     puls    x,pc
  1552.  
  1553. 1$:    jsr    mgetchr    ; get a character from the input
  1554.             ; line into accb
  1555.     jsr    tstdlm    ; test for a delimiter
  1556.     bne    6$    ; good delimiter if acca is non-zero
  1557.     subb    #'0    ; subtract ascii 0
  1558.     bmi    8$    ; error if less
  1559.  
  1560.     lda    ibcode    ; determine input base & go to right routine
  1561.     cmpa    #1    ; hex code ?
  1562.     beq    2$
  1563.  
  1564.     cmpa    #2    ; decimal code ?
  1565.     beq    4$
  1566.  
  1567.     cmpa    #3    ; octal code ?
  1568.     beq    5$
  1569.  
  1570.     ; hex input processing
  1571.  
  1572. 2$:    cmpb    #'9-'0    ; default an illegal input base to hex
  1573.     ble    3$    ; if 9 or less
  1574.     cmpb    #'A-'0
  1575.     bmi    8$    ; not hex if < A
  1576.     cmpb    #'F-'0
  1577.     bgt    8$    ; not hex if > F
  1578.     subb    #7    ; move A-F above 0-9
  1579.  
  1580. 3$:    bsr    9$    ; shift lo & hi bytes left 4 bits
  1581.     bsr    9$
  1582.     orb    nbrlo
  1583.     stb    nbrlo
  1584.     bra    1$
  1585.  
  1586.     ; decimal input
  1587.  
  1588. 4$:    cmpb    #9
  1589.     bgt    8$    ; not decimal if > 9
  1590.  
  1591.     ; multiply saved value by 10 & add in new digit
  1592.  
  1593.     bsr    10$    ; multiply current number by 2 to get 2x value
  1594.     ldx    nbrhi    ; save this *2 number temporarily
  1595.     stx    nbr2x
  1596.     bsr    9$    ; multiply this # by 4 to get 8x value
  1597.     clra        ; new digit <a,b>
  1598.     addd    nbr2x    ; note that 10x=2x+8x
  1599.     bcs    8$    ; carry out of ms byte is an error
  1600.     addd    nbrhi
  1601.     bcs    8$    ; carry out of ms byte is an error
  1602.     std    nbrhi    ; save result
  1603.     bra    1$
  1604.  
  1605.     ; octal input
  1606.  
  1607. 5$:    cmpb    #7
  1608.     bgt    8$    ; not octal if > 7
  1609.     bsr    9$    ; shift hi & lo bytes 3 places left
  1610.     bsr    10$    ; carry out of hibyte is illegal
  1611.     orb    nbrlo    ; add in new digit
  1612.     stb    nbrlo
  1613.     bra    1$
  1614.  
  1615. 6$:    ldx    linptr    ; good number - scan was successful
  1616.     stx    synptr    ; update good syntax line pointer
  1617.     lda    #1    ; set "good scan" flag
  1618.     puls    x,pc
  1619.  
  1620. 7$:    leas    2,s
  1621. 8$:    clra        ; conversion error - scan was unsuccessful
  1622.     deca
  1623.     puls    x,pc
  1624.  
  1625. 9$:    asl    nbrlo    ; shift a two byte number left one position
  1626.     rol    nbrhi
  1627.     bcs    7$
  1628. 10$:    asl    nbrlo    ; shift a two byte number left one position
  1629.     rol    nbrhi
  1630.     bcs    7$
  1631.     rts
  1632.  
  1633.     .page
  1634.     .sbttl    General Output Routines
  1635.  
  1636.     ;===========================================
  1637.     ; output a space
  1638.  
  1639. outsp:    lda    #' 
  1640.     jsr    outchr
  1641.     rts
  1642.  
  1643.     ;===========================================
  1644.     ; output an "=" sign
  1645.  
  1646. outeq:    lda    #'=
  1647.     jsr    outchr
  1648.     rts
  1649.  
  1650.     ;==========================================
  1651.     ; output a 1 byte number
  1652.  
  1653. out1by:    pshs    d
  1654.     ldb    #1
  1655.     bsr    outnum
  1656.     puls    d,pc
  1657.  
  1658.     ;==========================================
  1659.     ; output a 2 byte number
  1660.  
  1661. out2by:    pshs    d
  1662.     ldb    #2
  1663.     bsr    outnum
  1664.     puls    d,pc
  1665.  
  1666.     ;==========================================
  1667.     ; display the number pointed at by the address in the
  1668.     ; index register and output it according to the base
  1669.     ; specified in "dbcode"
  1670.     ; leading zeros are included
  1671.     ; acca & ix are preserved
  1672.     ; accb is input as the number of bytes comprising the
  1673.     ; number.
  1674.     ; global variables for external communication
  1675.     ; ibcode - input base code
  1676.     ; dbcode - display base code
  1677.     ;
  1678.     ; local variables
  1679.     ; decdig - decimal digit being built
  1680.     ; numbhi - hi byte of number being output
  1681.     ; numblo - lo byte of number being output
  1682.  
  1683. outnum:    pshs    d,x    ; save these
  1684.     ldx    ,x    ; get the two bytes at that address
  1685.     stx    numbhi    ; put them in a scratch area for processing
  1686.     lda    dbcode    ; get display base
  1687.  
  1688.     cmpa    #1
  1689.     beq    1$
  1690.     cmpa    #2
  1691.     beq    4$
  1692.     cmpa    #3
  1693.     beq    11$
  1694.     cmpa    #4
  1695.     beq    14$
  1696.  
  1697.     ; output a hex number
  1698.  
  1699. 1$:    aslb        ; 1 byte=2 chars, 2 bytes=4 chars
  1700. 2$:    bsr    16$    ; get next 4 bits
  1701.     bsr    16$
  1702.  
  1703.     anda    #0x0f    ; extract 4 bits
  1704.     cmpa    #9
  1705.     ble    3$
  1706.     adda    #7    ; convert 10:15 to A-F
  1707.  
  1708. 3$:    bsr    18$
  1709.     decb
  1710.     bne    2$
  1711.     puls    d,x,pc    ; restore registers & return
  1712.  
  1713.     ; output a decimal number
  1714.  
  1715. 4$:    decb        ; test # of bytes to output
  1716.     beq    5$
  1717.     ldx    #9$    ; initialize for output of a 2 byte number
  1718.     ldd    numbhi
  1719.     bra    6$
  1720.  
  1721. 5$:    ldx    #10$    ; initialize for output of a 1 byte number
  1722.     clra
  1723.     ldb    numbhi
  1724. 6$:    clr    decdig    ; clear the digit to output
  1725. 7$:    subd    ,x    ; subtract the power of 10 conversion constant
  1726.     bcs    8$    ; test for borrow (carry)
  1727.     inc    decdig    ; no borrow yet - nc digit being built
  1728.     bra    7$    ; repeat loop
  1729.  
  1730.     ; building of digit to output is complete - print it
  1731.  
  1732. 8$:    pshs    a    ; save lo byte of number being output
  1733.     lda    decdig    ; get digit
  1734.     bsr    18$    ; print it
  1735.     puls    a    ; restore lo byte
  1736.  
  1737.     addd    ,x++    ; borrow generated - cancel last subtraction
  1738.     cpx    #9$+10    ; are we thru with units conversion?
  1739.     bne    6$    ; if not, back to get next digit
  1740.     puls    d,x,pc    ; if yes, restore registers & return
  1741.  
  1742.     ; decimal output conversion constants
  1743.  
  1744. 9$:    .word    10000
  1745.     .word    1000
  1746. 10$:    .word    100
  1747.     .word    10
  1748.     .word    1
  1749.  
  1750.     ; output an octal number
  1751.  
  1752. 11$:    aslb        ; first approximation of # of
  1753.     clra        ; digits to output
  1754.     cmpb    #2
  1755.     bgt    12$
  1756.     bsr    16$    ; 1 byte - get first 2 bits
  1757.     bsr    18$
  1758.     bra    13$    ; go output last 2 digits
  1759.  
  1760. 12$:    bsr    17$    ; two byte # - output hi order bit/digit
  1761.     bsr    18$
  1762.     incb        ; 5 more digits to go
  1763.  
  1764. 13$:    bsr    16$    ; get next 3 bits
  1765.     bsr    17$
  1766.     anda    #7    ; extract 3 bits
  1767.     bsr    18$
  1768.     decb        ; count this digit
  1769.     bne    13$    ; are we done?
  1770.     puls    d,x,pc    ; if yes, restore registers & return
  1771.  
  1772. 14$:    aslb    ; output a binary number
  1773.     aslb
  1774.     aslb
  1775. 15$:    bsr    17$    ; get next bit
  1776.     anda    #1    ; extract the bit
  1777.     bsr    18$    ; output it
  1778.     decb        ; count it
  1779.     bne    15$    ; are we done?
  1780.     puls    d,x,pc    ; if yes, restore registers & return
  1781.  
  1782. 16$:    bsr    17$    ; left shift 2 bits
  1783.  
  1784. 17$:    asl    numblo    ; left shift the 3 byte number 1 bit
  1785.     rol    numbhi
  1786.     rola
  1787.     rts
  1788.  
  1789. 18$:    adda    #'0    ; convert to a numeric ascii digit & output it
  1790.     jsr    outchr
  1791.     rts
  1792.  
  1793.     .page
  1794.     .sbttl    Get Character Routines
  1795.  
  1796.     ;=================================================
  1797.     ; this routine gets the next character from the input
  1798.     ; line buffer
  1799.     ; acca is preserved
  1800.     ; accb is loaded with the character
  1801.     ; ix is incremented and left pointing to the character
  1802.     ; returned
  1803.  
  1804. mgetchr:
  1805.     ldx    linptr
  1806.     inx
  1807.     ldb    ,x
  1808.     stx    linptr
  1809.     clr    bolflg    ; set flag to not at "beginning of line"
  1810.     rts
  1811.  
  1812.     ;==================================================
  1813.     ; this routine gets the next character in the command
  1814.     ; lists
  1815.     ; acca is the character retrieved
  1816.     ; accb is preserved
  1817.     ; ix is incremented & left pointing to the character returned
  1818.  
  1819. getlst:    ldx    lisptr    ; get current list pointer
  1820.     inx        ; move pointer to next character
  1821.     lda    ,x    ; get character pointed at
  1822.     stx    lisptr    ; save pointer
  1823.     rts        ; and return
  1824.  
  1825.     .page
  1826.     .sbttl    Command Lists
  1827.  
  1828.     ;=====================================================
  1829.     ; command lists
  1830.     ;  a carriage return signifies end-of-command
  1831.     ;  a line feed signifies end-of-command-list
  1832.     ; list 1 - major commands
  1833.  
  1834. comlst:    .ascii    /BREAK/        ; set breakpoint (swi code)
  1835.     .byte    cr
  1836.     .ascii    /CONTINUE/    ; continue from "swi"
  1837.     .byte    cr
  1838.     .ascii    /COMPARE/    ; print sum & difference of 2 numbers
  1839.     .byte    cr
  1840.     .ascii    /COPY/        ; copy from one location to another
  1841.     .byte    cr
  1842.     .ascii    /DISPLAY/    ; display memory data
  1843.     .byte    cr
  1844.     .ascii    /DBASE/        ; set display base
  1845.     .byte    cr
  1846.     .ascii    /DELAY/        ; delay specified # of bytes
  1847.     .byte    cr
  1848.     .ascii    /DUMP/        ; dump memory in mikbug or image format
  1849.     .byte    cr
  1850.     .ascii    /GOTO/        ; go to memory address
  1851.     .byte    cr
  1852.     .ascii    /HELP/        ; help listing
  1853.     .byte    cr
  1854.     .ascii    /IBASE/        ; set input base
  1855.     .byte    cr
  1856.     .ascii    /LOAD/        ; load mikbug tape
  1857.     .byte    cr
  1858.     .ascii    /REG/        ; display registers
  1859.     .byte    cr
  1860.     .ascii    /SET/        ; set memory data
  1861.     .byte    cr
  1862.     .ascii    /SEARCH/    ; search memory for a byte string
  1863.     .byte    cr
  1864.     .ascii    /TEST/        ; test a range of memory
  1865.     .byte    cr
  1866.     .ascii    /VERIFY/    ; verify that memory content is unchanged
  1867.     .byte    cr
  1868.     .ascii    /CLI/        ; clear interrupt mask
  1869.     .byte    cr
  1870.     .ascii    /CLF/        ; clear fast interrupt mask
  1871.     .byte    cr
  1872.     .ascii    /SEI/        ; set interrupt mask
  1873.     .byte    cr
  1874.     .ascii    /SEF/        ; set fast interrupt mask
  1875.     .byte    cr
  1876.     .ascii    /IRQ/        ; set interrupt pointer
  1877.     .byte    cr
  1878.     .ascii    /FIRQ/        ; set fast interrupt pointer
  1879.     .byte    cr
  1880.     .ascii    /NMI/        ; set non-maskable interrupt pointer
  1881.     .byte    cr
  1882.     .ascii    /RSRVD/        ; set reserved interrupt pointer
  1883.     .byte    cr
  1884.     .ascii    /SWI/        ; set software interrupt pointer
  1885.     .byte    cr
  1886.     .ascii    /SWI2/        ; set swi2 interrupt pointer
  1887.     .byte    cr
  1888.     .ascii    /SWI3/        ; set swi3 interrupt pointer
  1889.     .byte    cr
  1890.     .byte    lf        ; end of list 1
  1891.  
  1892.     ; list 2 - modifier to dump
  1893.  
  1894.     .ascii    /TO/        ; destination
  1895.     .byte    cr
  1896.     .byte    lf        ; end of list 2
  1897.  
  1898.     ; list 3 - number base specifiers
  1899.  
  1900.     .ascii    /HEX/        ; base 16
  1901.     .byte    cr
  1902.     .ascii    /DEC/        ; base 10
  1903.     .byte    cr
  1904.     .ascii    /OCT/        ; base 8
  1905.     .byte    cr
  1906.     .ascii    /BIN/        ; base 2
  1907.     .byte    cr
  1908.     .byte    lf        ; end of list 3
  1909.  
  1910.     ; list 4 - information request
  1911.  
  1912.     .ascii    /?/
  1913.     .byte    cr
  1914.     .byte    lf        ; end of list 4
  1915.  
  1916.     ; list 5 - register names
  1917.  
  1918.     .ascii    /.CC/
  1919.     .byte    cr
  1920.     .ascii    /.A/
  1921.     .byte    cr
  1922.     .ascii    /.B/
  1923.     .byte    cr
  1924.     .ascii    /.DP/
  1925.     .byte    cr
  1926.     .ascii    /.IX/
  1927.     .byte    cr
  1928.     .ascii    /.IY/
  1929.     .byte    cr
  1930.     .ascii    /.IU/
  1931.     .byte    cr
  1932.     .ascii    /.AB/
  1933.     .byte    cr
  1934.     .ascii    /.PC/
  1935.     .byte    cr
  1936.     .ascii    /.SP/
  1937.     .byte    cr
  1938.     .byte    lf        ; end of list 5
  1939.  
  1940.     ; list 6 - modifiers to "display"
  1941.  
  1942.     .ascii    /DATA/
  1943.     .byte    cr
  1944.     .ascii    /USED/
  1945.     .byte    cr
  1946.     .byte    lf        ; end of list 6
  1947.  
  1948.     ; list 7 - modifier to "load"
  1949.  
  1950.     .ascii    /FROM/        ; source
  1951.     .byte    cr
  1952.     .byte    lf        ; end of list 7
  1953.  
  1954.  
  1955.     .page
  1956.     .sbttl    Get a line
  1957.  
  1958.     ;=======================================================
  1959.     ;
  1960.     ; this routine constructs a line of input by getting all
  1961.     ; input characters up to and including a carriage return
  1962.     ; (which then designates "end of line").
  1963.     ; typing rubout will delete the previous character
  1964.     ; typing control-c will abort the line
  1965.     ; typing control-z will use the previous line
  1966.     ; the input line is stored beginning at the address
  1967.     ; stored in bufbeg and ending at the address stored
  1968.     ; in bufend
  1969.     ; acca, accb, & ix are not preserved
  1970.     ;
  1971.     ; global variables
  1972.     ; bufbeg - input line start of buffer
  1973.     ; bufend - input line end of buffer
  1974.     ;
  1975.     ; local constants
  1976.  
  1977. getlin:    ldx    bufbeg    ; set pointer to one less than
  1978.             ; the beginning of the line buffer
  1979.     clrb        ; accb holds last input char
  1980. 1$:    cpx    bufend    ; check current line end against buffer end
  1981.     bne    2$
  1982.  
  1983.     ; line too long - abort it as if a control-c had been typed
  1984.  
  1985.     ldx    #msgltl    ; get message
  1986.     jsr    outstr    ; output it
  1987.     ldb    #3    ; put ctl-c in accb
  1988.     rts
  1989.  
  1990. 2$:    jsr    inpchr    ; get a character (returned in acca)
  1991.     anda    #0x7f    ; drop parity bit
  1992.  
  1993.     ; control-z copies from present position to previous end of line
  1994.  
  1995.     cmpa    #26    ; is char a control-z?
  1996.     bne    3$
  1997.     jsr    docrlf    ; yes, type cr-lf
  1998.     rts
  1999.  
  2000. 3$:    cmpa    #13    ; is char a cr?
  2001.     beq    4$
  2002.     cmpa    #10    ; or a lf?
  2003.     bne    6$
  2004. 4$:    inx
  2005.     sta    ,x    ; yes, store the terminator
  2006.     tst    hdxflg    ; test for half-duplex terminal
  2007.     bne    5$
  2008.     jsr    docrlf    ; type cr-lf
  2009. 5$:    rts        ; now return
  2010.  
  2011. 6$:    cmpa    #3    ; is char a control-c?
  2012.     bne    7$    ; no
  2013.     tab        ; return ctl-c in accb
  2014.     lda    #'^    ; echo an up-arrow
  2015.     jsr    outchr
  2016.     rts
  2017.  
  2018. 7$:    cmpa    #127    ; no, is it delete?
  2019.     beq    10$    ; yes - delete character
  2020.     inx        ; not a delete, so advance to next char
  2021.     sta    ,x    ; store it in inplin
  2022.     tab        ; last character in b
  2023.     tst    hdxflg    ; check half duplex
  2024.     bne    9$    ; yes - skip
  2025.     jsr    outchr    ; echo character
  2026. 9$:    bra    1$    ; get another
  2027.  
  2028.     ; current character is a delete
  2029.     ; test line length - if its zero, ignore this delete
  2030.     ; since we can't delete prior to first char in input line
  2031.  
  2032. 10$:    cpx    bufbeg
  2033.     beq    1$
  2034.     pshs    x
  2035.     ldx    #11$    ; delete character on screen
  2036.     bsr    outstr
  2037.     puls    x
  2038.     ldb    ,-x    ; last character
  2039.     bra    1$
  2040.  
  2041. 11$:    .byte  8,32,8,4    ; BS, SPACE, BS, EOT
  2042.  
  2043.  
  2044.     ;====================================================
  2045.     ; initialization routine
  2046.  
  2047. inital:    lda    #1
  2048.     sta    ibcode    ; set input base to hex
  2049.     sta    dbcode    ; set display base to hex
  2050.  
  2051.     ; set up display base number
  2052.  
  2053.     lda    #16
  2054.     sta    dbnbr
  2055.  
  2056.     ; max # of characters per line
  2057.  
  2058.     lda    #72
  2059.     sta    cplmax
  2060.     clr    inpflg    ; default input from terminal
  2061.     clr    outflg    ; default output to terminal
  2062.     clr    hdxflg    ; clear    half-duplex flag
  2063.  
  2064.     ; set up swi interrupt address pointer
  2065.  
  2066.     ldx    #typswi    ; type "swi" & do "reg" command
  2067.     stx    .swi
  2068.  
  2069.     ; clear breakpoint address
  2070.  
  2071.     ldd    #0xfffe    ; normal systems have rom here
  2072.     std    brkadr
  2073.  
  2074.     ; initialize to mondeb's command lists
  2075.  
  2076.     ldx    #comlst-1
  2077.     stx    comadr
  2078.  
  2079.     ; time constant for a .5 microsecond clock
  2080.  
  2081.     ldd    #285
  2082.     std    timcon
  2083.  
  2084.     .if    inituser
  2085.     jmp    userinit    ; user returns via rts
  2086.     .else
  2087.     rts
  2088.     .endif
  2089.  
  2090.     ;===================================================
  2091.     ; output a character string which begins at the address
  2092.     ; in the index register
  2093.     ; acca & accb are preserved
  2094.     ; ix is left pointing to the string terminator
  2095.  
  2096. outstr:    pshs    a
  2097. 1$:    lda    ,x    ; get char pointed to
  2098.     cmpa    #4    ; is it a string terminator?
  2099.     beq    2$    ; done if it is
  2100.     bsr    outchr    ; isn't, output it
  2101.     inx        ; on to next char
  2102.     bra    1$
  2103. 2$:    puls    a,pc
  2104.  
  2105.     ;=====================================================
  2106.     ; input a character
  2107.  
  2108. inpchr:    tst    inpflg    ; console ?
  2109.     bne    2$
  2110.  
  2111. 1$:    jsr    [conin]    ; tst for a character
  2112.     bcc    1$    ; none - loop until there is
  2113.     rts
  2114.  
  2115. 2$:    jsr    [altin]    ; tst for a character
  2116.     bcc    2$    ; none - loop until there is
  2117.     rts
  2118.  
  2119.     ;======================================================
  2120.     ; output the character in acca to the desired output
  2121.     ; device/location
  2122.     ; if outflg = 0, output is to terminal
  2123.     ; if outflg # 0, output is to address in outadr
  2124.     ;    & this address is then incremented
  2125.  
  2126. outchr:    pshs    d,x    ; save d and x
  2127.     ldb    outflg    ; test output destination flag
  2128.     decb
  2129.     ble    1$    ; skip this code if terminal output
  2130.  
  2131.     ; output to something other than terminal
  2132.  
  2133.     ldx    outadr    ; get output char destination addr
  2134.     sta    ,x+    ; save char in memory
  2135.     stx    outadr    ; update output address
  2136.     puls    d,x,pc
  2137.  
  2138. 1$:    cmpa    #lf    ; ignore line feeds
  2139.     bne    2$
  2140.     puls    d,x,pc
  2141.  
  2142. 2$:    cmpa    #cr    ; test for carriage return
  2143.     bne    3$
  2144.     bsr    docrlf
  2145.     puls    d,x,pc
  2146.  
  2147. 3$:    ldb    cplcnt    ; get "chars per line" count
  2148.     cmpb    cplmax
  2149.     bge    4$    ; send cr-lf if greater
  2150.  
  2151.     ; less than max, but also send cr-lf if 10 from end and
  2152.     ; printing a space
  2153.  
  2154.     addb    #10
  2155.     cmpb    cplmax
  2156.     blt    5$
  2157.     cmpa    #'     ; near end, test if about to print a space
  2158.     bne    5$
  2159.  
  2160.     ; terminal line full or nearly full - interject a cr-lf
  2161.  
  2162. 4$:    bsr    docrlf
  2163. 5$:    inc    cplcnt    ; bump counter
  2164.     bsr    chrout    ; send it to acia1
  2165.     puls    d,x,pc
  2166.  
  2167.     ;======================================================
  2168.     ; send a carriage return-line feed to the terminal
  2169.  
  2170. docrlf:    pshs    d
  2171.     lda    #cr
  2172.     bsr    chrout
  2173.     lda    #lf
  2174.     bsr    chrout
  2175.     clr    cplcnt    ; zero "chars/line" count
  2176.     puls    d,pc
  2177.  
  2178.     ;======================================================
  2179.     ; send char in acca
  2180.  
  2181. chrout:    tst    outflg    ; check destination
  2182.     bne    1$
  2183.     jmp  [conout]    ; output a character
  2184. 1$:    jmp  [altout]
  2185.  
  2186.     ;======================================================
  2187.     ; misc text
  2188.  
  2189. msghed:    .ascii    /MONDEB-09 1.00/
  2190.     .byte    cr,4
  2191. msgprm:    .byte    '*,4
  2192. msgswi:    .byte    cr,lf
  2193.     .ascii    /swi:/
  2194.     .byte    cr,lf,4
  2195. msgltl:    .ascii    /too long/
  2196.     .byte    4
  2197. msgnbr:    .ascii    /not set/
  2198.     .byte    4
  2199. msgbat:    .ascii    /set @ /
  2200.     .byte    4
  2201. msgver:    .ascii    /ok/
  2202.     .byte    4
  2203. msgnve:    .ascii    /checksum error /
  2204.     .byte    4
  2205. msgccl:    .ascii    /can't clear/
  2206.     .byte    4
  2207. msgcso:    .ascii    /can't set to ones/
  2208.     .byte    4
  2209. msgsis:    .ascii    /sum is /
  2210.     .byte    4
  2211. msgdis:    .ascii    /, dif is /
  2212.     .byte    4
  2213. msgs1:    .byte    cr,lf,0,0,'S,'1,4
  2214. msgs9:    .byte    cr,lf,0
  2215.     .ascii    /S9030000FC/
  2216.     .byte    cr,lf,4
  2217. msgcnh:    .ascii    /char not hex/
  2218.     .byte    cr,4
  2219.  
  2220.  
  2221.     ;****************************************************
  2222.     ;*            default interrupt transfers           *
  2223.     ;****************************************************
  2224.  
  2225.     .if    standalone
  2226. rsrvd:    jmp    [.rsrvd]    ; reserved vector
  2227. swi3:    jmp    [.swi3]        ; swi3 vector
  2228. swi2:    jmp    [.swi2]        ; swi2 vector
  2229. firq:    jmp    [.firq]        ; firq vector
  2230. irq:    jmp    [.irq]        ; irq vector
  2231. swi:    jmp    [.swi]        ; swi vector
  2232. nmi:    jmp    [.nmi]        ; nmi vector
  2233.     .endif
  2234.  
  2235.     .page
  2236.     .sbttl    dispatch table
  2237.  
  2238.     .if    standalone
  2239.  
  2240.     .area    DISPAT    (REL,CON)
  2241.  
  2242.     .word    timdel    ; time delay for # of ms specified by ix
  2243.     .word    cksum    ; return checksum of an address range in acca
  2244.     .word    mgetchr    ; return (in accb) char pointed to by linptr
  2245.     .word    getlst    ; return (in acca) char pointed to by lisptr
  2246.     .word    gtrang    ; pick up an address range in ranglo & ranghi
  2247.     .word    mnumber    ; pick up a number & return it in nbrhi & nbrlo
  2248.     .word    skpdlm    ; skip over input line delimiters
  2249.     .word    tstdlm    ; test char in accb for a delimiter
  2250.     .word    tsteol    ; test char in acca for end-of-line
  2251.     .word    comand    ; search specified command list for a command
  2252.     .word    typcmd    ; types out command number "comnum" in list acca
  2253.     .word    out1by    ; display the 1 byte number pointed at by ix
  2254.     .word    out2by    ; display the 2 byte number pointed at by ix
  2255.     .word    getlin    ; get a line of input into the tty buffer
  2256.     .word    outstr    ; output char string ix points to
  2257.     .word    docrlf    ; send cr-lf with delay & zero line count
  2258.     .word    outchr    ; like chrout, but with folding, cr delay, & lf
  2259.     .word    chrout    ; send acca to console
  2260.     .word    inpchr    ; get a char, return it in acca
  2261.     .word    prompt    ; to prompt for new command
  2262.     .word    mond09    ; start of mondeb
  2263.     .endif
  2264.  
  2265.     .page
  2266.     .sbttl    Hardware Interrupt Tables
  2267.  
  2268.     ;********************************************************
  2269.     ;*             MONDEB-09 hardware vector table
  2270.     ;*
  2271.     ;*  this table is used if the MONDEB-09 rom addresses
  2272.     ;*  the mc6809 hardware vectors.
  2273.     ;********************************************************
  2274.  
  2275.     .if    standalone
  2276.  
  2277.     .area    INTVEC    (ABS,OVR)
  2278.  
  2279.     . = 0xFFF0        ; vector position
  2280.  
  2281.     .word    rsrvd        ; reserved slot
  2282.     .word    swi3        ; software interrupt 3
  2283.     .word    swi2        ; software interrupt 2
  2284.     .word    firq        ; fast interrupt request
  2285.     .word    irq        ; interrupt request
  2286.     .word    swi        ; software interrupt
  2287.     .word    nmi        ; non-maskable interrupt
  2288.     .word    reset        ; restart
  2289.     .endif
  2290.